package com.voc.im.controller.account;

import com.jfoenix.controls.JFXSnackbar;
import com.voc.im.bean.Account;
import com.voc.im.controller.MainController;
import com.voc.im.manager.StageManager;
import com.voc.im.model.AccountModel;
import com.voc.im.xmpp.IMConnection;
import io.datafx.controller.FXMLController;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

@FXMLController("/fxml/account_login.fxml")
public class AccountLoginController {

    @FXML
    private Button btnGoRegister, btnConfirmLogin;
    @FXML
    private TextField fieldUsername, fieldPassword;

    @Inject
    private AccountModel accountModel;

    @PostConstruct
    public void init() throws Exception {

        btnGoRegister.setOnAction(this::onActionRegister);

        btnConfirmLogin.setOnAction(this::onActionConfirmLogin);

    }

    /**
     * 去注册点击事件
     */
    private void onActionRegister(ActionEvent event) {
        accountModel.setActionProperty("register");
    }

    /**
     * 提交登录表单
     */
    private void onActionConfirmLogin(ActionEvent event) {
        String username = fieldUsername.getText();
        String password = fieldPassword.getText();
        if (username.isEmpty()) {
            System.out.println("请输入账号！");
        }
        if (password.isEmpty()) {
            System.out.println("请输入密码！");
        }
        if (username.isEmpty() || password.isEmpty()) {
            return;
        }
        Account.Login login = new Account.Login(username, password);
        accountModel.setObjectProperty(new Account<>(login));
        accountModel.setActionProperty("status");
    }

}
